package com.rem.photoablum.dao;

import com.rem.photoablum.model.Album;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface AlbumDao extends JpaRepository<Album,Integer> {
    @Transactional
    @Modifying
    @Query(value = "insert into p_album(aid,pid,album_name,album_desc,topic,path) values(?1,?2,?3,?4,?5,?6) ",nativeQuery = true)
    int addAlbum(Long aid,Integer pid, String albumName,String albumDesc,String topic,String path);

    @Transactional
    @Modifying
    @Query(value = "update p_album set album_name = :albumName,album_Desc = :albumDesc,topic = :topic where aid =:aid",nativeQuery = true)
    int updateByAid(String albumName,String albumDesc,String topic,Long aid);

    @Transactional
    void deleteAllByAid(Long aid);

    List<Album> findAlbumByPid(Integer pid);

    Album findAlbumsByPidAndAlbumName(Integer pid,String albumName);

    Album findAlbumByAid(Long aid);

    Album findByAlbumName(String albumName);
}
